import { NzModalService } from 'ng-zorro-antd/modal';
import { AbsFormUtil } from '@abstract/form';
import { Component, OnInit } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { GriderList } from '@app/store/dict';
import { DiscloseService } from '@service/disclose.service';
import { NzMessageService } from 'ng-zorro-antd/message';
import { DiscloseListDetailComponent } from './disclose-list-detail/disclose-list-detail.component';
import { NzImageService } from 'ng-zorro-antd/image';
import { AuthService } from '@service/auth.service';
import { Auth } from '@app/store/auth.enum';
import { DiscloseListResultComponent } from './disclose-list-result/disclose-list-result.component';

// 0未处理，1，处理中，2审核未通过，3审核通过
@Component({
	selector: 'app-disclose-list',
	templateUrl: './disclose-list.component.html',
	styleUrls: ['./disclose-list.component.less']
})
export class DiscloseListComponent extends AbsFormUtil implements OnInit {

	nzLoading = false;
	data = [];
	griderList = GriderList;
	status = '2';

	authList = [];
	authEnum = Auth;
	constructor(
		private discloseService: DiscloseService,
		private nzMessageService: NzMessageService,
		private fb: FormBuilder,
		private nzModalService: NzModalService,
		private nzImageService: NzImageService,
		private authService: AuthService
	) {
		super();
		this.authList = this.authService.getAuth();
	}
	ngOnInit() {
		this.buildForm();
		this.onSearch(true);

	}

	buildForm() {
		this.validateForm = this.fb.group({
			discloseTitle: []
		});
	}

	async onSearch(isPageInit?: boolean) {
		this.nzLoading = true;
		if (isPageInit) {
			this.page.page = 1;
		}
		const formValue = this.validateForm.value;
		const params = { ...formValue, ...this.page };
	
		const result = await this.discloseService.getDiscloseList(params);
		this.data = result.data.list;
		this.page.total = result.data.totalCount;
		this.nzLoading = false;

	}




	detail(item) {
		this.nzModalService.create({
			nzTitle: '爆料详情',
			nzContent: DiscloseListDetailComponent,
			nzWidth: '60%',
			nzOkText: null,
			nzComponentParams:{
				item: item
			}
		});
	}
	result(item) {
		this.nzModalService.create({
			nzTitle: '处理结果',
			nzContent: DiscloseListResultComponent,
			nzWidth: '70%',
			nzOkText: null,
			nzComponentParams:{
				id: item?.id
			}
		});
	}
	async handle(component, item) {
		const {id, treatResult } = item;
		if (!treatResult) {
			this.nzMessageService.error('处理内容不能为空');
			return false;
		}
		component.hide();
		await this.discloseService.saveDisclose({discloseId: id, treatResult});
		this.nzMessageService.success('处理成功');
	
		this.onSearch();
	}
	async verify(component, item) {
		const {id, verifyResult, treatId } = item;
		if (!verifyResult && this.status === '2') {
			this.nzMessageService.error('审核内容不能为空');
			return false;
		}
		component.hide();
		await this.discloseService.updateDisclose({discloseId: id, verifyResult: verifyResult ? verifyResult : '审核通过', id: treatId, status: this.status});
		this.nzMessageService.success('审核成功');
		this.onSearch();
	}
	viewImage(item) {
		const {imageUrl1, imageUrl2} = item;
		const images = [];
		if (imageUrl1) {
			images.push({
				src: imageUrl1
			})
		}
		if (imageUrl2) {
			images.push({
				src: imageUrl2
			})
		}
		this.nzImageService.preview(images, { nzZoom: 1.5, nzRotate: 0 });
	}
}
